# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=arbtt
pkgver=0.12.0.2
pkgrel=23
pkgdesc="Automatic Rule-Based Time Tracker"
url="http://arbtt.nomeata.de/"
license=("GPL2")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-x11' 'haskell-aeson' 'haskell-attoparsec' 'haskell-bytestring-progress'
         'haskell-conduit' 'haskell-pcre-light' 'haskell-resourcet' 'haskell-strict'
         'haskell-terminal-progress-bar' 'haskell-tz' 'haskell-unliftio-core' 'haskell-utf8-string')
makedepends=('ghc' 'haskell-process-extras' 'haskell-tasty' 'haskell-tasty-golden'
             'haskell-tasty-hunit')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('46ebd0c7d71e0a0f6d17d8f6d45338977f5343bcd331e1c68eb8cb14575a5208')

build() {
  cd $pkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --datasubdir=haskell-arbtt --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie' 

  runhaskell Setup build $MAKEFLAGS
}

check() {
  cd $pkgname-$pkgver
  (
    for _exe in arbtt-{dump,import,recover,stats}; do
      PATH="$PWD/dist/build/$_exe:$PATH"
    done
    runhaskell Setup test --show-details=direct
  )
}

package() {
  cd $pkgname-$pkgver

  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
